﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Linq;
using DataAccessLayer;


namespace BusinessAccessLayer
{
    public class BAThanhPho
    {
        
        QuanLyBanHangDataContext dbs = new QuanLyBanHangDataContext();
        public DataTable getTable()
        {
           
            DataTable tp = new DataTable();
            tp.Columns.Add("MaTP",typeof(string));
            tp.Columns.Add("TenTP",typeof(string));
            foreach (var item in dbs.ThanhPhos.ToList())
            {
                DataRow row = tp.NewRow();
                row["MaTP"] = item.ThanhPho1;
                row["TenTP"] = item.TenThanhPho;
                tp.Rows.Add(row);

            }
            return tp;
        }
   
       
        public bool ThemThanhPho(string maTP, string tenTP)
        {
            bool f = false;
            try
            {
                ThanhPho tp = new ThanhPho()
                {
                    ThanhPho1 = maTP,
                    TenThanhPho = tenTP
                };
                dbs.ThanhPhos.InsertOnSubmit(tp);
                dbs.SubmitChanges();
                f = true;
            }
            catch 
            {
                f = false;
            }
            return f;
        }
        public bool XoaThanhPho(string maTP)
        {
            bool f = false;
            try
            {
                ThanhPho thpho = dbs.ThanhPhos.Single(tp => tp.ThanhPho1 == maTP);
                dbs.ThanhPhos.DeleteOnSubmit(thpho);
                dbs.SubmitChanges();
                f = true;
            }
            catch
            {
                f = false;
            }
            return f;

        }
        public bool SuaThanhPho(string maTP, string tenTP)
        {
            bool f = false;
            try
            {
                ThanhPho thpho = dbs.ThanhPhos.Single(tp => tp.ThanhPho1 == maTP);
                thpho.TenThanhPho = tenTP;
                dbs.SubmitChanges();
                f = true;
            }
            catch
            {
                f = false;
            }
            return f;
        }
       
    }
}
